Repository navigation
fix: memoize readability, instagram and tiktok per document, not per url - #894
Conversation
readability(url, html), instagram's getDescription(url, $) and tiktok's getAuthorAndUsername(url, $) were memoized with EqualityFirstArgument, so a second document at the same url, such as the same page fetched with other headers, another proxy or prerendered, got the first document's answer. They now use EqualityUrlAndHtmlDom, like metascraper-iframe, which still reuses the result across the rules of one extraction. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Problem
metascraper-readability,metascraper-instagramandmetascraper-tiktokmemoize a parse withmemoizeOne.EqualityFirstArgument, so the cached result is keyed on the url alone:readability(url, html, opts)(packages/metascraper-readability/src/index.js)getDescription(url, $)(packages/metascraper-instagram/src/index.js)getAuthorAndUsername(url, $)(packages/metascraper-tiktok/src/index.js)The memo lives at module level, so it is shared by every call in the process. A second document at the same url (the same page fetched with other headers, through another proxy, or prerendered vs not) gets the first document's
description,dateorauthor. Found in the Microlink API, where concurrent requests for one url with different HTML returned the earlier document's description.Fix
Use
memoizeOne.EqualityUrlAndHtmlDom, the comparatormetascraper-iframealready uses. The result is still reused across the rules of one extraction (same url, same document), and recomputed for a new document.Tests
Each package gets a test that runs two different documents at the same url and expects each to be read on its own. All three fail before the fix (tiktok returned
First Authorfor the second document) and pass after:standardis clean on the three packages.After release
The Microlink API carries this as a pnpm patch on
metascraper-readability@5.58.7(MR !2109). Once this is released, bumpingmetascraper*there lets the patch go.🤖 Generated with Claude Code
Note
Medium Risk
Behavior change for repeated URLs with different HTML affects extraction correctness in concurrent or variant-page scenarios; scope is limited to three scraper packages with regression tests.
Overview
Fixes incorrect metadata when the same URL is scraped with different HTML (e.g. concurrent Microlink requests). Module-level memoization in metascraper-readability, metascraper-instagram, and metascraper-tiktok used
memoizeOne.EqualityFirstArgument, so the cache key was only the URL and the first document’s parsed result was reused for later HTML.All three now use
memoizeOne.EqualityUrlAndHtmlDom(same pattern as metascraper-iframe): one parse is still shared across rules for a single extraction, but a new document triggers a fresh parse.Each package adds a test that runs two distinct HTML payloads at the same URL and asserts metadata reflects the second document independently (dates, descriptions, authors).
Reviewed by Cursor Bugbot for commit 8f5ca45. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit